/**
 * xml工具类接口
 * 初始化 YCL.XML('xmlstr')或YCL.XML('xmlpath')
 * xmlstr是指一段xml格式字符串
 * xmlpath是指xml文件的目录
 */
(function () {
    this.YCL.xml = function (s) {
        var Dom, isFile = s.substring(s.length - 4, s.length).toUpperCase() === '.XML',
            IE = function () {
                var dom = new ActiveXObject("Msxml2.domdocument");
                dom.async = false;
                (isFile) ? dom.load(s) : dom.loadXML(s);
                return dom.documentElement || dom;
            }, NoIE = function () {
                if (isFile) {
                    var dom = document.implementation.createDocument("", "", null);
                    dom.async = false;
                    dom.load(s);
                    return dom;
                } else {
                    return new DOMParser().parseFromString(s, "text/xml");
                }
            };
        Dom = (Browser.ie)?IE():NoIE();
        //todo 如果有selectNodes以及selectSingleNode则不用扩展.要继续修改
        return {
            /**
             * 将Dom对象转为xml字符串
             * @return {*}
             */
            toString:function () {
                if (Browser.ie) {
                    return Dom.xml;
                } else {
                    var oSerializer = new XMLSerializer();
                    return oSerializer.serializeToString(Dom);
                }
            },
            /**
             * 根据xpath查找一组Nodes
             * @param xPath
             */
            selectNodes:function(xPath){
               if(Browser.ie){
                   return Dom.selectNodes(xPath);
               }else{
                   //Dom.createNSResolver(Dom);
               }
            }
        };
    };
})();
